package com.deparse.dpframe.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

/**
 * Created by hsy on 2016/3/4.
 */
public class DPDuplicateStateLayout extends LinearLayout {
    public DPDuplicateStateLayout(Context context) {
        super(context);
    }

    public DPDuplicateStateLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public DPDuplicateStateLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        duplicateState(this);
    }

    private void duplicateState(ViewGroup vg) {
        for (int i = 0; i < vg.getChildCount(); i++) {
            View child = getChildAt(i);
            child.setDuplicateParentStateEnabled(true);
            if (child instanceof ViewGroup) {
                duplicateState((ViewGroup) child);
            }
        }
    }
}
